# @Version        : 1.0
# @Update Time    : 2024/7/4 23:29
# @File           : dept_crud.py
# @IDE            : PyCharm
# @Desc           : 文件描述信息
from advanced_alchemy.base import BigIntAuditBase

from src.core.base.orm.orm import AbstractORMModel
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import String, Integer, ForeignKey, BigInteger, Index


# class SysDept(AbstractORMModel):
#     __tablename__ = "sys_dept"
#     __table_args__ = {"comment": "部门表"}
#     dept_name: Mapped[str] = mapped_column(
#         String(20), nullable=False, comment="部门名称"
#     )
#     parent_id: Mapped[int] = mapped_column(Integer, default=0, comment="父级ID")
#     ancestors: Mapped[str] = mapped_column(String(255), comment="祖级列表")
#     status: Mapped[str] = mapped_column(
#         String(1), default="1", comment="帐号状态（1正常 2停用）"
#     )
#     leader: Mapped[str | None] = mapped_column(String(20), comment="部门领导")
#     phone: Mapped[str | None] = mapped_column(String(11), comment="电话")
#     order_num: Mapped[int] = mapped_column(Integer, comment="排序")
#     remark: Mapped[str | None] = mapped_column(String(500), comment="备注")



class SysDept(BigIntAuditBase):
    __tablename__ = "sys_dept"
    __table_args__ = (
        Index("ix_sys_dept_parent_id", "parent_id"),
        Index("ix_sys_dept_status", "status"),
        {"comment": "部门表"},
    )

    dept_name: Mapped[str] = mapped_column(
        String(20), nullable=False, comment="部门名称"
    )
    parent_id: Mapped[int | None] = mapped_column(
        BigInteger,
        ForeignKey("sys_dept.id", ondelete="SET NULL"),
        nullable=True,
        comment="父级ID",
    )
    ancestors: Mapped[str] = mapped_column(String(255), comment="祖级列表")
    status: Mapped[str] = mapped_column(
        String(1), default="1", comment="帐号状态（1正常 2停用）"
    )
    leader: Mapped[str | None] = mapped_column(String(20), comment="部门领导")
    phone: Mapped[str | None] = mapped_column(String(11), comment="电话")
    order_num: Mapped[int] = mapped_column(Integer, comment="排序")
    remark: Mapped[str | None] = mapped_column(String(500), comment="备注")
